package com.ruoyi.service.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.ServiceMycart;
import com.ruoyi.service.service.IServiceMycartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购物车Controller
 * 
 * @author ZDL
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/service/mycart")
public class ServiceMycartController extends BaseController
{
    @Autowired
    private IServiceMycartService serviceMycartService;

    /**
     * 查询购物车列表
     */
    @PreAuthorize("@ss.hasPermi('service:mycart:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServiceMycart serviceMycart)
    {
        startPage();
        List<ServiceMycart> list = serviceMycartService.selectServiceMycartList(serviceMycart);
        return getDataTable(list);
    }

    /**
     * 导出购物车列表
     */
    @PreAuthorize("@ss.hasPermi('service:mycart:export')")
    @Log(title = "购物车", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceMycart serviceMycart)
    {
        List<ServiceMycart> list = serviceMycartService.selectServiceMycartList(serviceMycart);
        ExcelUtil<ServiceMycart> util = new ExcelUtil<ServiceMycart>(ServiceMycart.class);
        util.exportExcel(response, list, "购物车数据");
    }

    /**
     * 获取购物车详细信息
     */
    @PreAuthorize("@ss.hasPermi('service:mycart:query')")
    @GetMapping(value = "/{mycartId}")
    public AjaxResult getInfo(@PathVariable("mycartId") Long mycartId)
    {
        return success(serviceMycartService.selectServiceMycartByMycartId(mycartId));
    }

    /**
     * 新增购物车
     */
    @PreAuthorize("@ss.hasPermi('service:mycart:add')")
    @Log(title = "购物车", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceMycart serviceMycart)
    {
        return toAjax(serviceMycartService.insertServiceMycart(serviceMycart));
    }

    /**
     * 修改购物车
     */
    @PreAuthorize("@ss.hasPermi('service:mycart:edit')")
    @Log(title = "购物车", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceMycart serviceMycart)
    {
        return toAjax(serviceMycartService.updateServiceMycart(serviceMycart));
    }

    /**
     * 删除购物车
     */
    @PreAuthorize("@ss.hasPermi('service:mycart:remove')")
    @Log(title = "购物车", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mycartIds}")
    public AjaxResult remove(@PathVariable Long[] mycartIds)
    {
        return toAjax(serviceMycartService.deleteServiceMycartByMycartIds(mycartIds));
    }
}
